/* eslint-disable func-style */
/* eslint-disable @typescript-eslint/no-explicit-any */
import "synckit";
import "systemjs";

const SystemModule: {
  (): ClassDecorator;
  imports: (key?: string) => ParameterDecorator;
  exports: (key: string, value: any) => any;
  __cache: Record<string, any>;
} = (() => {
  const SystemModule = function SystemModule(): ClassDecorator {
    return function (target) {
      SystemModule.__cache[target.name] = target;
      return target;
    };
  };
  SystemModule.exports = function (key: string, value: any) {
    return ((SystemModule as any)[key] = value);
  };
  SystemModule.imports = function (key?: string): ParameterDecorator {
    return function (target: any, propertyKey: any) {
      Object.defineProperty(target, propertyKey, {
        set(value: any) {
          SystemModule.exports(key ?? propertyKey, value);
        },
        get() {
          return SystemModule.__cache[key ?? propertyKey];
        },
        enumerable: true,
        configurable: true,
      });
    };
  };
  SystemModule.__cache = {} as Record<string, any>;
  return SystemModule;
})();

// > systemjs 6.3.3
@SystemModule()
export class AppEffect {
  constructor(
    @SystemModule.imports()
    public angular: ng.IAngularStatic,
  ) {
    function initApp() {
      const App = angular.module("root", [
        "ngSanitize",
        "ngTouch",
        "ngAnimate",
        "ngAria",
        "ngMessages",
        "ngResource",
        "ui.bootstrap",
        // "modern module", just register here.
        "ui.router",
      ]);
      return App;
    }
    // eslint-disable-next-line no-constructor-return
    return SystemModule.exports("default", initApp);
  }
}
